
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Helper;
using IRepository;
using Models;
using System.Linq;
using Models.Entity;
using MySql.Data.MySqlClient;
using Dapper;
using System.Data;
using System.Linq.Expressions;

namespace Repository
{
    /// <summary>
    /// 图片处理服务
    /// </summary>
    public class WeekCourseReplaceRepository : IWeekCourseReplaceRepository
    {
        DapperHelper<CWeekCourseReplaceEntity> dbHelper = new DapperHelper<CWeekCourseReplaceEntity>();

        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="key">主键 ID</param>
        /// <returns></returns>
        public async Task<ResultObj<int>> Delete(int key){
            ResultObj<int> reObj = new ResultObj<int>();
            reObj.data = await dbHelper.Delete(i => i.id == key);
            reObj.success = reObj.data > 0;
            return reObj;
        }

        /// <summary>
        /// 保存
        /// </summary>
        /// <param name="inEnt"></param>
        /// <returns></returns>
        public async Task<ResultObj<int>> Save(DtoSave<CWeekCourseReplaceEntity> inEnt)
        {

            ResultObj<int> reObj = new ResultObj<int>();
            if (inEnt.data.id == 0)
            {
                inEnt.data.id = await SequenceRepository.GetNextID<CWeekCourseReplaceEntity>();
                reObj.data = await dbHelper.Save(inEnt);
            }
            else
            {
                reObj.data = await dbHelper.Update(inEnt);
            }

            reObj.success = reObj.data > 0;
            return reObj;
        }
    }
}
